package top.chmin.project.cloud.sys.table.info;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import top.chmin.project.cloud.common.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;



/**
 * chmin
 * 2024-01-25 14:19:37
 * cloud-code
 */
public class TableInfoCondition extends Condition {
    private TableInfoCondition parent = null;

    TableInfoCondition() {
    }

    private TableInfoCondition(TableInfoCondition condition) {
        this.parent = condition;
    }

    public static TableInfoCondition forDelete() {
        TableInfoCondition condition = new TableInfoCondition();
        condition.setSql("DELETE FROM sys_table_info#where##group##order##limit#");
        return condition;
    }

    public static TableInfoCondition forSelect() {
        TableInfoCondition condition = new TableInfoCondition();
        condition.modelClass = TableInfo.class;
        condition.setSql("SELECT #select# FROM sys_table_info#where##group##order##limit#");
        return condition;
    }

    public TableInfoCondition distinct() {
        this.distinct = true;
        return this;
    }

    public TableInfoCondition limit(int limit) {
        this.limit = " LIMIT " + limit;
        return this;
    }

    public TableInfoCondition sub() {
        return new TableInfoCondition(this);
    }

    public TableInfoCondition finish() {
        if (!whereList.isEmpty()) {
            parent.whereList.add("(" + String.join(" OR ", whereList) + ")");
        }
        parent.whereValueList.addAll(whereValueList);
        return parent;
    }

    public TableInfo selectFirst() {
        return selectFirst(TableInfo.class);
    }

    public List<TableInfo> selectList() {
        return selectList(TableInfo.class);
    }

    public Stream<TableInfo> selectStream() {
        return selectStream(TableInfo.class);
    }

    public Page<TableInfo> selectPage() {
        return selectPage(TableInfo.class);
    }

    /*###########auto#start###########*/
    public static int deleteByTableCode(String tableCode) {
        return forDelete().tableCode().eq(tableCode).execute();
    }

    public static TableInfo selectByTableCode(String tableCode) {
        return forSelect().tableCode().eq(tableCode).selectFirst(TableInfo.class);
    }

    public static <T> T selectByTableCode(String tableCode, Class<T> clazz) {
        return forSelect().tableCode().eq(tableCode).selectFirst(clazz);
    }

    public static int deleteByTableName(String tableName) {
        return forDelete().tableName().eq(tableName).execute();
    }

    public static TableInfo selectByTableName(String tableName) {
        return forSelect().tableName().eq(tableName).selectFirst(TableInfo.class);
    }

    public static <T> T selectByTableName(String tableName, Class<T> clazz) {
        return forSelect().tableName().eq(tableName).selectFirst(clazz);
    }

    /*###########auto##end############*/
    /* append $conditionIndexAppender$ */
    /*###########auto#start###########*/
    public CreateBy createBy() {
        return new CreateBy();
    }

    public class CreateBy extends StringFlexColumn<TableInfoCondition> {
        private CreateBy() {
            super(TableInfoCondition.this, "create_by");
        }
    }

    public CreateTime createTime() {
        return new CreateTime();
    }

    public class CreateTime extends LocalDateTimeFlexColumn<TableInfoCondition> {
        private CreateTime() {
            super(TableInfoCondition.this, "create_time");
        }
    }

    public Id id() {
        return new Id();
    }

    public class Id extends IntegerFlexColumn<TableInfoCondition> {
        private Id() {
            super(TableInfoCondition.this, "id");
        }
    }

    public Prefix prefix() {
        return new Prefix();
    }

    public class Prefix extends StringFlexColumn<TableInfoCondition> {
        private Prefix() {
            super(TableInfoCondition.this, "prefix");
        }
    }

    public TableCode tableCode() {
        return new TableCode();
    }

    public class TableCode extends StringFlexColumn<TableInfoCondition> {
        private TableCode() {
            super(TableInfoCondition.this, "table_code");
        }
    }

    public TableComment tableComment() {
        return new TableComment();
    }

    public class TableComment extends StringFlexColumn<TableInfoCondition> {
        private TableComment() {
            super(TableInfoCondition.this, "table_comment");
        }
    }

    public TableName tableName() {
        return new TableName();
    }

    public class TableName extends StringFlexColumn<TableInfoCondition> {
        private TableName() {
            super(TableInfoCondition.this, "table_name");
        }
    }

    public UpdateBy updateBy() {
        return new UpdateBy();
    }

    public class UpdateBy extends StringFlexColumn<TableInfoCondition> {
        private UpdateBy() {
            super(TableInfoCondition.this, "update_by");
        }
    }

    public UpdateTime updateTime() {
        return new UpdateTime();
    }

    public class UpdateTime extends LocalDateTimeFlexColumn<TableInfoCondition> {
        private UpdateTime() {
            super(TableInfoCondition.this, "update_time");
        }
    }

    /*###########auto##end############*/
    /* append $conditionFieldAppender$ */
}
